package marseillaisdu90.student_life;

import marseillaisdu90.modele.Liste_code;
import marseillaisdu90.modele.Personnage;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

public class BoiteDialogEntrerCodeSecret {

	private Context context;
	private Liste_code lc;
	private AlertDialog alert;
	private Personnage p;
	
	public BoiteDialogEntrerCodeSecret(Liste_code lc, Context context) {
		
		this.context = context;
		this.lc = lc;
		alert = null;
		
	}
	
	public void nouveauCode(Personnage perso){
		
		this.p = perso;
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setTitle("Code secret");
		builder.setMessage("Pour entrer dans la salle il faut un code\nSaisir le code :");
		builder.setCancelable(true);
		
		final EditText input = new EditText(context);
		input.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
		builder.setView(input);
		
		builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {}
		});
		
		builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				if(!input.getText().toString().equals("")) {
					Toast.makeText(context, lc.liste_code.get(p.getNumInteraction()).estBon(), 3000).show();
					if(lc.liste_code.get(p.getNumInteraction()).Codebon()) {
						MonApplication.modele.ListePiece.id.get(MonApplication.modele.nopiece_courante).supprimerPerso(p.getNom());
						MonApplication.modele.ListePiece.id.get(MonApplication.modele.nopiece_courante).topographie[p.getPosY()][p.getPosX()]=0;
					}
					
					MonApplication.getSl().mettreAJourMenu();
					
				}
				else {
					Toast.makeText(context, "Veuillez choisir un code !!", 2000).show();
					alert.show();
				}
			}
		});
		alert = builder.create();
		alert.show();
		
		Log.i("fonction terminé", "fonction terminé");
		
	}
	
}
